package icon

import (
	"fmt"
	"github.com/gofiber/fiber/v2"
	"io/fs"
	"path/filepath"
	"strings"
)

func GetAllIcon(ctx *fiber.Ctx) error {
	var data []string

	// 遍历media/icons,获取所有图标名称
	iconPath := "./static/icons"
	err := filepath.Walk(iconPath, func(path string, info fs.FileInfo, err error) error {
		if strings.Contains(info.Name(), ".png") {
			data = append(data, info.Name())
		}
		return err
	})

	if err != nil {
		return ctx.JSON(fiber.Map{
			"status":  "error",
			"message": fmt.Sprintf("ICON遍历失败！%v", err),
		})
	}

	return ctx.JSON(fiber.Map{
		"status":  "done",
		"message": "请求成功！",
		"data":    data,
	})
}
